# -*- coding: utf-8 -*-

#   Copyright (C) 2011  P.L. Lucas, P.L. del Castillo
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

import pygtk
pygtk.require('2.0')
import gtk

from picture import *

class VideoPropertiesDialog:
	def __init__(self, parent, videoProperties):
		self.videoProperties=videoProperties
		self.dialog= gtk.Dialog("Project properties", parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
		
		self.dialog.vbox.pack_start( self.video_init() )
		self.dialog.vbox.pack_start( self.sound_init() )
		
		res=self.dialog.run()
		if res==gtk.RESPONSE_ACCEPT:
			self.set_entry('width', 'int')
			self.set_entry('height', 'int')
			self.set_entry('framespersecond', 'int')
			if not self.sound_check.get_active():
				self.videoProperties.sound_path=''
			else:
				self.videoProperties.sound_path=self.sound_filechooserbutton.get_filename()
		self.dialog.destroy()
	
	def set_entry(self,name,type_):
		eval( compile('self.videoProperties.'+name+'='+type_+'(self.'+name+'_entry.get_text())', '<string>', 'exec') )
	
	def text_entry(self, label, name):
		area1=gtk.HBox()
		l=gtk.Label(label)
		area1.pack_start(l, False, False)
		eval( compile('self.'+name+'_entry=gtk.Entry()', '<string>', 'exec') )
		eval( compile('self.'+name+'_entry.set_text(str(self.videoProperties.'+name+'))', '<string>', 'exec') )
		eval( compile('area1.pack_start(self.'+name+'_entry, False, False)', '<string>', 'exec') )
		area1.show_all()
		return area1
	
	def video_init(self):
		frame=gtk.Frame('Video')
		area=gtk.VBox()
		area.pack_start(self.text_entry('Width:', 'width'),False,False)
		area.pack_start(self.text_entry('Height:', 'height'),False,False)
		area.pack_start(self.text_entry('Frames per second:', 'framespersecond'),False,False)
		area.show_all()
		frame.add(area)
		frame.show_all()
		return frame
	
	def sound_init(self):
		frame=gtk.Frame('Sound')
		area=gtk.VBox()
		self.sound_filechooserbutton = gtk.FileChooserButton('Select a File')
		self.sound_filechooserbutton.set_filename(self.videoProperties.sound_path)
		area.pack_start(self.sound_filechooserbutton,False,False)
		self.sound_check=gtk.CheckButton('Activate sound')
		self.sound_check.set_active( self.videoProperties.sound_path!='' )
		area.pack_start(self.sound_check,False,False)
		area.show_all()
		frame.add(area)
		frame.show_all()
		return frame
		
		
